﻿using Forum.Model.Entity;
using SqlSugar;
using Forum.Model;

namespace Forum.Infrastructure
{
    public class DbContext
    {
        public static SqlSugarClient MySql = new SqlSugarClient(new ConnectionConfig()
        {
            ConnectionString = SecretConfig.DBConnectionString,//连接符字串
            DbType = DbType.MySql, //数据库类型
            IsAutoCloseConnection = true //不设成true要手动close
        });

        public static SqlSugarClient Oracle = new SqlSugarClient(new ConnectionConfig()
        {
            ConnectionString = "User ID=sa;Password=P@ssw0rd;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 2333))) (CONNECT_DATA = (SERVICE_NAME = EWMT)))",//连接符字串
            DbType = DbType.Oracle, //数据库类型
            IsAutoCloseConnection = true //不设成true要手动close
        });

        public static void InitDataBase()
        {
            //初始化数据库:如果不存在则创建数据库
            MySql.DbMaintenance.CreateDatabase();
           
            //模拟测试数据
            //List<NewsInfo> news = new List<NewsInfo>() {
            //     new NewsInfo(){
            //        Guid=Guid.NewGuid().ToString().ToUpper(),
            //        NewsTitle="卖火柴的小女孩",
            //        NewsContent="hello",
            //        NewsAuthor="安徒生",
            //        NewsType=1,
            //        ViewTimes=10,
            //        NewsDate=DateTime.Now.AddDays(-100)
            //     },
            //     new NewsInfo(){
            //        Guid= Guid.NewGuid().ToString().ToUpper(),
            //        NewsTitle="草房子",
            //        NewsContent="hello",
            //        NewsAuthor="曹文轩",
            //        NewsType=1,
            //        ViewTimes=10,
            //        NewsDate=DateTime.Now.AddDays(-100)
            //     }
            //};
            ////写入测试数据
            //MySql.Insertable(news).ExecuteCommand();
        }
    }
}
